package org.itstack.command;

public class LightOnCommand implements Command{
    
    private final Light light;
    //记录前一个状态
    private boolean wasOn;

    
        

    public LightOnCommand(Light light) {
        this.light = light;
    }

    @Override
    public void undo() {
        if(!wasOn){
            light.on();
        }
    }

    @Override
    public void execute() {
     
        wasOn = light.isOn();
        light.on();
    }

}
